package com.meevle.model
{
	import flash.desktop.NativeApplication;
	import flash.filesystem.File;
	
	public class ApplicationInfo
	{
		private static var instance:ApplicationInfo;
		
		private static var appXML:XML;
		private static var ns:Namespace;
		

		public function ApplicationInfo(enforcer:SingletonEnforcer) {
		if (enforcer == null) {
				throw new Error( "You Can Only Have One ApplicationInfo" );
			}
		}

		public static function getInstance() : ApplicationInfo {
			if (instance == null) {
				instance = new ApplicationInfo( new SingletonEnforcer );
				getAppXML();
			}
			return instance;
		}
		
		private static function getAppXML():Boolean {
			appXML = NativeApplication.nativeApplication.applicationDescriptor;
			ns = appXML.namespace();
			
			var _rtn:Boolean = false;
			if(appXML != null){
				_rtn = true;
			} else {
				throw new Error("NativeApplication applicationDescriptor could not be loaded");
			}
			return _rtn;
		}
		
		public function get appID():String {
			return appXML.ns::id[0];
		}
		
		public function get appVersion():String {
			return appXML.ns::version[0];
		}
		
		public function get appName():String {
			return appXML.ns::name[0];
		}
		
		public function get appFilename():String {
			return appXML.ns::filename[0];
		}
		
		public function get appDescription():String {
			return appXML.ns::description[0];
		}
		
		public function get appCopyright():String {
			return appXML.ns::copyright[0];
		}

		public function get appIcon16URL():String {
			return XML(appXML).*::icon.*::image16x16;
		}
		
		public function get appIcon32URL():String {
			return XML(appXML).*::icon.*::image32x32;
		}
		
		public function get appIcon48URL():String {
			return XML(appXML).*::icon.*::image48x48;
		}
		
		public function get appIcon128URL():String {
			return XML(appXML).*::icon.*::image128x128;
		}
		
		public function get applicationStorageDirectory():String {
			return File.applicationStorageDirectory.nativePath;
		}
		
		public function get rtmpServerURI():String {
			return "rtmp://192.168.1.1/Meevle";
		}
		
		public function get httpServerURI():String {
			return "http://192.168.1.1:5080/Meevle";
		}
		
		public function get fileUploadServerURI():String {
			return "http://192.168.1.1:5080/Meevle/FileUploadServlet";
		}
	}
}

// Utility Class to Deny Access to Constructor
class SingletonEnforcer {}